<template>
	<view class="mysport">
		<view class="top">
			<view style="display: flex;">
				<u-icon :name="userinfo.overt?'eye-fill':'eye-off'"></u-icon>
			<view>
				公开运动记录
			</view>
			</view>
			<view>
				<u-switch v-model="userinfo.overt" @change="change" :loading="loading" ></u-switch>
			</view>
			
		</view>
		<u-line></u-line>
		<block v-for="(item,index) in sportLsit" :key="item.moid" v-if="sportLsit.length>0">
			<view class="runRes">
				<view>
					<text class="num">{{item.distance}}</text>
					<text>公里</text>
				</view>
				<view class="detail">
					<view class="time">
						<text>{{item.runTime}}</text>
						<text>时长</text>
					</view>
					<view class="vraSpd">
						<text>{{item.avgPace}}</text>
						<text>平均配速</text>
					</view>
					<view class="heat">
						<text>{{item.calorie}}</text>
						<text>热量(千卡)</text>
					</view>
				</view>
				<view class="endtime">结束时间  {{item.endTime}}</view>
			</view>
		</block>
		<view class="tips" v-if="!sportLsit.length>0">暂无运动记录</view>
	</view>
</template>

<script>
	import { mapState, mapActions } from 'vuex'
	import { onesSportList,changeUserInfo } from '@/config/api.js'
	export default {
		data() {
			return {
				sportLsit: [],
				loading:false
			}
		},
		onLoad() {
			this.loadOnesSport();
			console.log(this.userinfo);
		},
		computed: {
			...mapState(['userinfo'])
		},
		methods: {
			...mapActions(['updateuserinfo' ]),
			async loadOnesSport() {
				const { rows: data } = await onesSportList(this.userinfo.pid)
				this.sportLsit = data
			},
			async change(e) {
				this.loading = true;
				const res = await changeUserInfo(this.userinfo);
				this.updateuserinfo(res.data);
				this.loading = false;
			},
		}
	}
</script>

<style lang="less" scoped>
	.top{
		display: flex;
		flex-direction: row;
		height: 80rpx;
		align-items: center;
		justify-content: space-between;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
	.runRes {
		width: 96vw;
		height: 320rpx;
		margin: 20rpx auto;
		background: linear-gradient(to left top, #63b7af, #abf0e9);
		border-radius: 10rpx;
		color: #fff;
		text-align: center;
		overflow: hidden;
	}
	.runRes .num {
		display: block;
		font-size: 80rpx;
	}
	.runRes .detail {
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		padding: 20rpx 30rpx;
	}
	.runRes .detail text {
		display: block;
	}
	.runRes .endtime{
		margin-bottom: 20rpx;
	}
	.tips {
		line-height: 100vh;
		text-align: center;
		color: #a1a1a1;
	}
</style>